<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>调拨发起编辑</title>
	<%@ include file="/common/metaInput.jsp"%>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script src="${ctx}/js/jsp/date.js" type="text/javascript"></script>
	<script type="text/javascript">
	var basic_Url = "${ctx}/logic/allocatoutwh";
	var addressGrid;
	$(function(){
		//单据状态
		var billSt = '${actoutwh.zd002Status}';
		//表格
		var column1 = [{ display: 'id', name: 'id',type: 'string',hide : true},
	    			   { display: 'zd002MaterId', name: 'zd002MaterId',hide : true},
	    			   { display: '<font color="gray">编码</font>', name: 'zd003Code',width: 100},
	    			   { display: '<font color="gray">名称</font>', name: 'zd004Name',width: 100},
	    			   { display: '<font color="gray">类型</font>', name: 'zd004Name',width: 100},
	    			   { display: '<font color="gray">规格</font>', name: 'zd006Spec' ,width: 100},
	    			   { display: '<font color="gray">型号</font>', name: 'zd007Model' ,width: 100},
	    			   { display: '<font color="gray">颜色</font>', name: 'zd009Color' ,width: 100},
	    			   { display: '<font color="gray">材质</font>', name: 'zd010Quality' ,width: 100},
	    			   { display: '<font color="gray">大小</font>', name: 'zd011Size' ,width: 120},
	    			   { display: '<font color="gray">单位</font>', name: 'zd012Unit', width: 100 },
	    			   { display: '<font color="gray">单价</font>', name: 'zd014Price', width: 100 },
	    			   { display: '<font color="gray">含税单位</font>', name: 'zd015TaxPrice', width: 100 },
	    			   { display: '<font color="gray">库存数量</font>', name: 'zd019HsQuantity',width: 100,render:function(item){
	    					if(item.zd019HsQuantity==''||item.zd019HsQuantity==null){
	    						return "0.0";
	    					}else{
	    						return item.zd019HsQuantity;	
	    					}
	    				}},
						{ display: '本次出库数量<font color="red">*</font>', name: 'zd017Quantity',width: 150,editor : {type :'float'}}
						];
		var column2 = [{ display: 'id', name: 'id',type: 'string',hide : true},
	    			   { display: 'zd002MaterId', name: 'zd002MaterId',hide : true},
	    			   { display: '<font color="gray">编码</font>', name: 'zd003Code',width: 100},
	    			   { display: '<font color="gray">名称</font>', name: 'zd004Name',width: 100},
	    			   { display: '<font color="gray">类型</font>', name: 'zd005Type',width: 100},
	    			   { display: '<font color="gray">规格</font>', name: 'zd006Spec' ,width: 100},
	    			   { display: '<font color="gray">型号</font>', name: 'zd007Model' ,width: 100},
	    			   { display: '<font color="gray">颜色</font>', name: 'zd009Color' ,width: 100},
	    			   { display: '<font color="gray">材质</font>', name: 'zd010Quality' ,width: 100},
	    			   { display: '<font color="gray">大小</font>', name: 'zd011Size' ,width: 120},
	    			   { display: '<font color="gray">单位</font>', name: 'zd012Unit', width: 100 },
	    			   { display: '<font color="gray">单价</font>', name: 'zd014Price', width: 100 },
	    			   { display: '<font color="gray">含税单价</font>', name: 'zd015TaxPrice', width: 100 },
	    			   { display: '<font color="gray">库存数量</font>', name: 'zd019HsQuantity',width: 100 },
						{ display: '本次出库数量<font color="red">*</font>', name: 'zd017Quantity',width: 150 }];
		var column3 = column1;
		if(''==billSt && 'ADD'=='${flag}'){
			//新增
			column3 = column1;
		}else{
			if('OUTWH_SAVE'==billSt || 'OUTWH_BACK'==billSt){
				column3 = column1;
			}else{
				column3 = column2;
			}
		}
		addressGrid = $("#dataGrid1").ligerGrid({
			columns: column3,
	        enabledEdit : true,width : '99%',height : '90%',
	        usePager: true,pageSize:1000,pageSizeOptions:[1000],
			rownumbers : false,checkbox : true,
			parms:[{ name : 'actoutwhId' , value : '${actoutwh.id}'}],
	        url : basic_Url+"/gridItems.do",
			toolbar : { 
				items : [ { text : '新增', disable : true,click : function() {
						if($("#zd003OutWhId").val()==''){
							$.dialog.alert("请先选择出库仓库");
							return false;
						}else{
							getDG().dialog({
								title:'物料选择', width : 800, height : 400,
								content: 'url:' + sys_context+'/public/windowalert/itemaff.do?code=' + $("#zd003OutWhCode").val(),
								lock : true, max : true, min : true,
								ok: function(){
									var rows = this.content.getSelected();
									if (rows != null) {
										for (var i=0; i<rows.length; i++){
											var row = rows[i];
											addressGrid.addRow2({
												zd002MaterId : row.id,
												zd003Code : row.zd004MaterialsCode,
												zd004Name : row.zd005MaterialsName,
												zd005Type : row.maType,
												zd006Spec : row.zd006MaterialsSpec,
												zd007Model : '',
												zd009Color : '',
												zd010Quality : '',
												zd011Size : '',
												zd012Unit : row.zd008Unit,
												zd019HsQuantity : row.zd009Quantity
											});
										}
									}
		           					this.content.Close();
						    		return false;
							    },
							    cancelVal: '关闭',
							    cancel: true
							}).zindex();
						}
					},icon: 'add' },{ line : true }, 
					{ text : '删除', click : function(){
						addressGrid.deleteSelectedRow();
					},
					img : '${ctx}/js/ligerUI/skins/icons/delete.gif'
					}
				]
			}			
		});
		<%--
		//送货仓库
		$("#zd003OutWhId").change(function(){ 
			$("#zd003OutWhCode").val($("#zd003OutWhId").find("option:selected").attr("cvalue"));
			$("#zd003OutWhName").val($("#zd003OutWhId").find("option:selected").text());
			var manager = $("#dataGrid1").ligerGetGridManager(); 
			manager.loadData(); 
		}); 
		//收货仓库
		$("#zd004InWhId").change(function(){ 
			$("#zd004InWhCode").val($("#zd004InWhId").find("option:selected").attr("cvalue"));
			$("#zd004InWhName").val($("#zd004InWhId").find("option:selected").text());
		}); 
		--%>
	 	$("#inputForm").validate({
			onsubmit : true,
			//执行ajaxsubmit  
			submitHandler : function(editform) {

				try {
					url = basic_Url + "/save.do";
					var api = frameElement.api;
					var W = api.opener;
					getReturnMessage(url, "inputForm", W.searchAP);
				} catch (e) {
					alert(e);
				}
			}
		}); 
	 	//按钮
	 	if(billSt=='' || '${flag}'=='ADD'){
			//新增
			$("#forExcel").hide();
			$("#forSubmit").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else if(billSt=='OUTWH_SAVE'){
			//暂存
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else if(billSt=='OUTWH_SUBMIT'){
			//已提交待二审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forSubmit").hide();
			$("#forApproved").hide();
		}else if(billSt=='OUTWH_AUDIT'){
			//已二审待三审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forSubmit").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
		}else if(billSt=='OUTWH_APPROVE'){
			//已三审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
		}else if(billSt=='OUTWH_BACK'){
			//已驳回
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else{
			
		}
	});
	//提交
	function submitForm(param) {
		var data = $("#dataGrid1").ligerGetGridManager().getData();
		var del = $("#dataGrid1").ligerGetGridManager().getDeleted();
		if(data.length==0){
			$.dialog.alert("请增加物料信息");
	   	 	return false;
		}
		var ba=true;
		if($("#zd003OutWhId").val()==$("#zd004InWhId").val()){
			 $.dialog.alert("您的送货仓与收货仓一样，请修改！");
        		ba = false;
        		return;
		}
		if(data !=null){ 
			for (var i = 0;i < data.length;i++){
				var row = data[i];
				if(undefined == row.zd012Unit || row.zd012Unit==null || row.zd012Unit==''){
					$.dialog.alert("您第"+(i+1)+"行的单位没有选择");
	           		ba = false;
	           		return;
				}
				if(undefined == row.zd017Quantity || row.zd017Quantity==null || row.zd017Quantity <= 0){
	           	 $.dialog.alert("您第"+(i+1)+"行的调拨数量不合法");
	           		ba = false;
	           		return;
	            }
				if((parseFloat(row.zd017Quantity))>parseFloat(row.zd019HsQuantity)){
					$.dialog.alert("您第" + (i+1) + "行的调拨数量大于库存数量");
					ba = false;
					return false;
				}
			}
		}
		if (ba){
			$("#dataItem").val(JSON.stringify(data));
			$("#datadele").val(JSON.stringify(del));
			$("#flagMark").val(param);
			$("#inputForm").submit();
		}
	}
	//收货仓
	function  SotrageinfoOutWindow() {
		getDG().dialog(
				{
					title : '选择仓库',
					width : 650,
					height : 350,
					content : 'url:' + sys_context + '/public/windowalert/sotrageinfo.do?',    
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var rows = this.content.getSelected();
						if(rows==null){
							$.dialog.alert("请选择数据");
							return;
						}
						else{
							if(rows.length>1){
								$.dialog.alert('只能选择一行数据!');
								return;
							}else{
								$(rows).each(function() {
									$("#zd003OutWhId").val(this.id);
									$("#zd003OutWhCode").val(this.zd002Code);
									$("#zd003OutWhName").val(this.zd003Name);
							  });
							}
						}
						
						this.content.Close();
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
	//送货仓
	function  SotrageinfoIntWindow() {
		getDG().dialog(
				{
					title : '选择仓库',
					width : 650,
					height : 350,
					content : 'url:' + sys_context + '/public/windowalert/sotrageinfo.do?',    
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var rows = this.content.getSelected();
						
						if(rows==null){
							$.dialog.alert("请选择数据");
							return;
						}
						else{
							if(rows.length>1){
								$.dialog.alert('只能选择一行数据!');
								return;
							}else{
								$(rows).each(function() {
									$("#zd004InWhId").val(this.id);
									$("#zd004InWhCode").val(this.zd002Code);
									$("#zd004InWhName").val(this.zd003Name);
									
							});
							}
						}
						this.content.Close();
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
	function close(){
		var api = frameElement.api;
		var W = api.opener;
		CloseDialog();
		W.searchAP();
	}
	
</script>

</head>

<body onload="">
<form id="inputForm" action="" method="post">
	<input type="hidden" id="id" name="id" value="${actoutwh.id}" />
	<input type="hidden" id="bizVersion" name="bizVersion" value="${actoutwh.bizVersion}" />
	<input type="hidden" id="datadele" name="datadele" value=""/>
	<input type="hidden" id="dataItem" name="dataItem" value=""/>
	<input type="hidden" id="flagMark" name="flagMark" value=""/>
	<!-- 用于标识提交按钮 -->
	<input type="hidden" id="submitFlag" value="" />
		<div class="pageContent">
			<div class="panel">
				<table class="TableBlock" align="center">
					<c:if test="${!empty actoutwh.zd001Code}">
					<tr >
						<td nowrap="nowrap" width="20%">调拨发起单号:</td>
						<td width="30%">
							<input id="zd001Code" name="zd001Code" readonly="readonly"  class="inp_width_98p" value="${actoutwh.zd001Code}" />
						</td>
						<td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%">
							<input class="inp_width_98p" type="text" id="bizCreatorDate" name="bizCreatorDate"
							value="<fmt:formatDate value="${actoutwh.bizCreatorDate}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/>
						</td>
					</tr>
					</c:if>
					<tr>
						<td nowrap="nowrap" width="20%">送货仓:</td>
						<td width="30%">
							<!-- 
							<select id="zd003OutWhId" class="inp_width_98p required" name="zd003OutWhId">
						 		<option></option>
								<c:forEach items='${whList}' var='wh'>
   		                 			<option id='${wh.id}' value='${wh.id}' cvalue="${wh.zd002Code }" <c:if test="${actoutwh.zd003OutWhId eq wh.id }">selected</c:if>>${wh.zd003Name}</option>
   		                 		</c:forEach>
							</select> -->
							<input type="hidden" id="zd003OutWhId" name="zd003OutWhId" value="${actoutwh.zd003OutWhCode }"/>
							<input type="hidden" id="zd003OutWhCode" name="zd003OutWhCode" value="${actoutwh.zd003OutWhCode }"/>
							<input type="text" id="zd003OutWhName" name="zd003OutWhName" value="${actoutwh.zd003OutWhName }" class="inp_width_98p required"/>
						    <input type="button" value="..."  onclick="SotrageinfoOutWindow();" />
   		             	</td>
						<td nowrap="nowrap" width="20%">收货仓:</td>
						<td width="30%">
						<!--  
							<select id="zd004InWhId" class="inp_width_98p required" name="zd004InWhId" >
								<option></option>
								<c:forEach items='${whList}' var='wh'>
   		                 			<option id='${wh.id}' value='${wh.id}' cvalue="${wh.zd002Code }" <c:if test="${actoutwh.zd004InWhId eq wh.id }">selected</c:if>>${wh.zd003Name}</option>
   		                 		</c:forEach>
							</select>
					    -->
							<input type="hidden" id="zd004InWhId" class="inp_width_98p required" name="zd004InWhId"/>
							<input type="hidden" id="zd004InWhCode" name="zd004InWhCode" value="${actoutwh.zd004InWhCode }"/>
							<input type="text" id="zd004InWhName" name="zd004InWhName" value="${actoutwh.zd004InWhName }" class="inp_width_98p required"/>
							<input type="button"  value="..."  onclick="SotrageinfoIntWindow();" />
   		             	</td>
					</tr>
					<tr>
						<td nowrap="nowrap" width="20%">转库日期:</td>
						<td width="30%">
							<input id="zd005MoveDate" name="zd005MoveDate" class="inp_width_98p required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
							value="<fmt:formatDate value="${actoutwh.zd005MoveDate}" pattern="yyyy-MM-dd" type="both" />" />
							<c:if test="${actoutwh.zd005MoveDate == null}">
								<script>
									var date = new Date();
									$("#zkrq").val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
								</script>
							</c:if>
						</td>
						<td nowrap="nowrap" width="20%">制单人:</td>
						<td width="30%">
						<c:choose>
						   <c:when test="${empty actoutwh}">
						      <input type="text" id="bizCreatorName" name="bizCreatorName" class="inp_width_98p" value="${user.name}" readonly="readonly"/>
						   </c:when>
						   <c:otherwise>
						   	<input type="text" id="bizCreatorName" name="bizCreatorName" class="inp_width_98p" value="${actoutwh.bizCreatorName}" readonly="readonly"/>
						   </c:otherwise>
						</c:choose>
						</td>
					</tr>
   		           	<tr>
   		           		<td>备注:</td>
   		           		<td colspan="3"><input id="zd008Remark" type="text" class="inp_width_98p" name="zd008Remark" value="${actoutwh.zd008Remark}" /></td>
   		           	</tr>
					<tr>
						<td colspan="4" style="margin-bottom: 10px;">
							<div id="dataGrid1"></div>
						</td>  
					</tr>
				</table>
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forSave" onclick="submitForm('OUTWH_SAVE')">保存</button></div></div></li>
					<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forSubmit" onclick="submitForm('OUTWH_SUBMIT')">提交</button></div></div></li>
					<webres:displaycontroller elementId="LOGIC_TRSTART_RK_ZG" description="调拨发起单二级审核">
				       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forAudit" onclick="submitForm('OUTWH_AUDIT')" title="提交二级审核">二级审核</button></div></div></li>
			       	</webres:displaycontroller>
					<webres:displaycontroller elementId="LOGIC_TRSTART_RK_WJ" description="调拨发起单二审完结">
				       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forAuditEnd" onclick="submitForm('OUTWH_APPROVE')">二审完结</button></div></div></li>
			       	</webres:displaycontroller>
			        <webres:displaycontroller elementId="LOGIC_TRSTART_RK_JL" description="调拨发起单三审完结">
				       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forApproved" onclick="submitForm('OUTWH_APPROVE')">三审完结</button></div></div></li>
				    </webres:displaycontroller>   
				    <webres:displaycontroller elementId="LOGIC_TRSTART_RK_BH" description="调拨发起单驳回">
				       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forBack" onclick="submitForm('OUTWH_BACK')">驳回</button></div></div></li>
			       </webres:displaycontroller>  
		       		<li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
				</ul>
			</div>
		</div>
	</form>
</body>
</html>
